package com.fire.control.system.module.excel.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import com.fire.control.system.dto.UserDTO;
import com.fire.control.system.module.common.controller.BaseController;
import com.fire.control.system.module.excel.service.ExcelService;
import com.fire.control.system.support.protocol.comman.ResponseJsonProtocol;
import com.fire.control.system.support.protocol.comman.ResponseProtocol;
import com.fire.control.system.support.protocol.device.DeviceRequestProtocol;


/**
 * 
 * @ClassName:  ExcelController
 * @Description:  导入导出excel控制器
 * @author:  xiechengguang
 * @date:  2017年6月24日 下午6:32:54
 *
 */
@Controller
@RequestMapping("/web/excel")
public class ExcelController extends BaseController {
	private static final Logger log = LoggerFactory.getLogger(ExcelController.class);
	
	@Autowired private ExcelService excelService;
	
	/**
	 * @author: xiechengguang 
	 * @Title: exportExcel   
	 * @Description: 导出excel  
	 * @param:        
	 * @return: void      
	 * @throws
	 */
	@RequestMapping(value = "/exportExcel")  
	public void exportExcel(HttpServletRequest request, HttpServletResponse response, DeviceRequestProtocol reqProtocol) {
		UserDTO userDTO = getUser();
		String companyId = userDTO.getCompany().getId();
		reqProtocol.setCompanyId(companyId);
		excelService.export(request, response, reqProtocol);  
	}
	
	// 暂无此方法
	@RequestMapping(value = "/importExcel")  
	public ResponseProtocol importExcel(@RequestParam(value="file") MultipartFile file)  throws IOException {  
    	if(file.isEmpty()){
    		log.info("EXCEL导入，文件为空");
			return null;
		}
//    	ImportExcelDto dto = new ImportExcelDto();
    	Object dto = new Object();
    	// 利用反射将excel的值封装到Object中，并返回（A）
    	List<Object> list = excelService.importDataFromExcel(dto, file.getInputStream(), file.getOriginalFilename()); 
    	// 调用一个方法，将上一步的返回结果，进行操作：B调用（A）
    	return new ResponseJsonProtocol();
	}
	
	
	
}
